package com.op.parcel.boot.config;

import com.baomidou.mybatisplus.core.parser.ISqlParser;
import com.baomidou.mybatisplus.extension.injector.LogicSqlInjector;
import com.baomidou.mybatisplus.extension.parsers.BlockAttackSqlParser;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PerformanceInterceptor;
import com.baomidou.mybatisplus.extension.plugins.SqlExplainInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.ArrayList;
import java.util.List;

/**
 * mybatisPlus 配置
 *
 * @author xuan🐽
 */
@Configuration
@EnableTransactionManagement
@MapperScan("com.op.parcel.**.mapper.**")
public class MybatisPlusConfig {

	@Bean
	public PaginationInterceptor paginationInterceptor() {
		return new PaginationInterceptor();
	}

	@Bean
	public LogicSqlInjector logicSqlInjector() {
		return new LogicSqlInjector();
	}

//	/**
//	 * 执行分析
//	 *
//	 * @return
//	 */
//	@Bean
//	@Profile({"dev", "test"})
//	public SqlExplainInterceptor sqlExplainInterceptor() {
//		SqlExplainInterceptor sqlExplainInterceptor = new SqlExplainInterceptor();
//		List<ISqlParser> sqlParserList = new ArrayList<>();
//		sqlParserList.add(new BlockAttackSqlParser());
//		sqlExplainInterceptor.setSqlParserList(sqlParserList);
//		return sqlExplainInterceptor;
//	}

	/**
	 * 性能分析
	 *
	 * @return
	 */
	@Bean
	@Profile({"dev", "test"})
	public PerformanceInterceptor performanceInterceptor() {
		return new PerformanceInterceptor();
	}

}

